package com.rslai.commons.validator.jsonvalidator.matchers;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

/**
 * 最小值Matcher
 */
public class MinNumber extends TypeSafeMatcher<Number> {
    Number minNumber;

    /**
     * 构造函数
     * @param minNumber minNumber
     */
    public MinNumber(Number minNumber) {
        this.minNumber = minNumber;
    }

    /**
     * 安全匹配，将永远不会为空
     * @param number number
     * @return boolean
     */
    @Override
    public boolean matchesSafely(Number number) {
        return minNumber.doubleValue() <= number.doubleValue();
    }

    /**
     * 产生描述
     * @param description 描述
     */
    @Override
    public void describeTo(Description description) {
        description.appendText("最小值是 ").appendValue(minNumber);
    }

    @Factory
    public static Matcher<Number> min(Number minNumber) {
        return new MinNumber(minNumber);
    }

}
